package com.dashuaibran.joker;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

import com.mysql.cj.jdbc.PreparedStatement;

/**
 * Hello world!
 *
 */
public class App {
	public static void main(String[] args) throws Exception {
		// 1.注册驱动
		// DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
		Class.forName("com.mysql.cj.jdbc.Driver");
		// 2.获取链接
		Connection connection = DriverManager.getConnection("jdbc:mysql://39.96.203.253:3306/test", "test",
				"66c3b24ff4");
		// 3.获取操作数据库的预处理对象
		PreparedStatement pstmPreparedStatement = (PreparedStatement) connection
				.prepareStatement("select * from game_account");
		// 4.执行sql语句得到结果
		ResultSet resultSet = pstmPreparedStatement.executeQuery();
		// 5.遍历结果集
		while (resultSet.next()) {
			System.out.println(resultSet.getString("name"));

		}

		resultSet.close();
		pstmPreparedStatement.close();
		connection.close();

	}
}
